package com.neusmart.common.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.neusmart.common.R;
import com.neusmart.common.util.MToast;
import com.neusmart.common.view.slidingmenu.SlidingFragmentActivity;
import com.neusmart.common.view.slidingmenu.SlidingMenu;

/**
 * Sliding BaseActivity
 * <p/>
 * roy
 */
public class SlidingBaseActivity extends SlidingFragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // set the Behind View
        setBehindContentView(R.layout.menu_frame);

        // customize the SlidingMenu
        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.x128);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
        sm.setTouchModeBehind(SlidingMenu.TOUCHMODE_MARGIN);

        sm.setMode(SlidingMenu.LEFT);
        setContentView(R.layout.content_frame);
    }

    protected void setMenu(Fragment fragment) {
        setFragment(R.id.menu_frame, fragment);
    }

    protected void setContent(Fragment fragment) {
        setFragment(R.id.content_frame, fragment);
    }

    public void setFragment(int resId, Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(resId, fragment)
                .commitAllowingStateLoss();
    }

    public void showToast(int resId) {
        MToast.showText(this, resId);
    }

    public void showToast(String msg) {
        MToast.showText(this, msg);
    }
}
